package com.cxm.weilai.util;


import org.apache.commons.lang3.StringUtils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * String工具包
 *
 * @author admin
 */
public class StringUtil {

    private static Pattern regex = Pattern.compile("\\{(.*?)\\}");

    /**
     * 编码
     */
    public static String escape(String src) {
        StringBuffer tmp = new StringBuffer();
        tmp.ensureCapacity(src.length() * 6);

        for (int i = 0; i < src.length(); i++) {
            char index = src.charAt(i);

            if ((Character.isDigit(index)) || (Character.isLowerCase(index)) || (Character.isUpperCase(index))) {
                tmp.append(index);
            } else if (index < 'Ā') {
                tmp.append("%");
                if (index < '\020') {
                    tmp.append("0");
                }
                tmp.append(Integer.toString(index, 16));
            } else {
                tmp.append("%u");
                tmp.append(Integer.toString(index, 16));
            }
        }
        return tmp.toString();
    }

    /**
     *
     */
    public static String replaceVariable(String template, Map<String, String> map) throws Exception {
        Pattern regex = Pattern.compile("\\{(.*?)\\}");
        Matcher regexMatcher = regex.matcher(template);
        while (regexMatcher.find()) {
            String key = regexMatcher.group(1);
            String toReplace = regexMatcher.group(0);
            String value = map.get(key);
            if (value != null) {
                template = template.replace(toReplace, value);
            } else {
                throw new Exception(new StringBuilder().append("没有找到[").append(key).append("]对应的变量值，请检查表变量配置!").toString());
            }
        }
        return template;
    }

    /**
     *
     */
    public static String replaceVariable(String template, String repaceStr) {
        Pattern regex = Pattern.compile("\\{(.*?)\\}");
        Matcher regexMatcher = regex.matcher(template);
        if (regexMatcher.find()) {
            String toReplace = regexMatcher.group(0);
            template = template.replace(toReplace, repaceStr);
        }
        return template;
    }

    /**
     * 解编码
     */
    public static String unescape(String src) {
        StringBuffer tmp = new StringBuffer();
        tmp.ensureCapacity(src.length());
        int lastPos = 0;
        int pos = 0;

        while (lastPos < src.length()) {
            pos = src.indexOf("%", lastPos);
            if (pos == lastPos) {
                if (src.charAt(pos + 1) == 'u') {
                    char ch = (char) Integer.parseInt(src.substring(pos + 2, pos + 6), 16);

                    tmp.append(ch);
                    lastPos = pos + 6;
                } else {
                    char ch = (char) Integer.parseInt(src.substring(pos + 1, pos + 3), 16);

                    tmp.append(ch);
                    lastPos = pos + 3;
                }
            } else if (pos == -1) {
                tmp.append(src.substring(lastPos));
                lastPos = src.length();
            } else {
                tmp.append(src.substring(lastPos, pos));
                lastPos = pos;
            }
        }

        return tmp.toString();
    }

    /**
     * 判断是否存在
     */
    public static boolean isExist(String content, String begin, String end) {
        String tmp = content.toLowerCase();
        begin = begin.toLowerCase();
        end = end.toLowerCase();
        int beginIndex = tmp.indexOf(begin);
        int endIndex = tmp.indexOf(end);
        if ((beginIndex != -1) && (endIndex != -1) && (beginIndex < endIndex)) {
            return true;
        }
        return false;
    }

    /**
     * 去首空格
     */
    public static String trimPrefix(String toTrim, String trimStr) {
        while (toTrim.startsWith(trimStr)) {
            toTrim = toTrim.substring(trimStr.length());
        }
        return toTrim;
    }

    /**
     * 去尾空格
     */
    public static String trimSufffix(String toTrim, String trimStr) {
        while (toTrim.endsWith(trimStr)) {
            toTrim = toTrim.substring(0, toTrim.length() - trimStr.length());
        }
        return toTrim;
    }

    /**
     * 去空格
     */
    public static String trim(String toTrim, String trimStr) {
        return trimSufffix(trimPrefix(toTrim, trimStr), trimStr);
    }

    /**
     * 若原字符串为Null则返回空字符串,否则剪去字符串两端的空格及控制字符.
     *
     * @param src 传入参数
     * @return String
     */
    public static String trim(String src) {
        if (src == null) {
            return "";
        }
        return src.trim();
    }

    public static String escapeHtml(String content) {
//        return StringEscapeUtils.escapeHtml(content);
        return "";
    }

    public static String unescapeHtml(String content) {
//        return StringEscapeUtils.unescapeHtml(content);
        return "";
    }

    /**
     * 判断是否空
     */
    public static boolean isEmpty(String str) {
        if (str == null) {
            return true;
        }
        if (str.trim().equals("")) {
            return true;
        }
        return false;
    }

    public static boolean isNotEmpty(String str) {
        return !isEmpty(str);
    }

    /**
     * 截取字符串
     */
    public static String subString(String str, int len) {
        int strLen = str.length();
        if (strLen < len) {
            return str;
        }
        char[] chars = str.toCharArray();
        int cnLen = len * 2;
        String tmp = "";
        int index = 0;
        for (int i = 0; i < chars.length; i++) {
            int indexChar = chars[i];
            if (indexChar <= 128) {
                index += 1;
            } else {
                index += 2;
            }
            if (index >= cnLen) {
                break;
            }
            tmp = new StringBuilder().append(tmp).append(String.valueOf(chars[i])).toString();
        }
        return tmp;
    }

    /**
     * 判断是否是数字
     */
    public static boolean isNumberic(String string) {
        if (StringUtils.isEmpty(string)) {
            return false;
        }
        boolean rtn = validByRegex("^[-+]{0,1}\\d*\\.{0,1}\\d+$", string);
        if (rtn) {
            return true;
        }

        return validByRegex("^0[x|X][\\da-eA-E]+$", string);
    }

    /**
     * 判断整数
     */
    public static boolean isInteger(String string) {
        boolean rtn = validByRegex("^[-+]{0,1}\\d*$", string);
        return rtn;
    }

    /**
     * 判断是否日期
     */
    public static boolean isDate(String str) {
        boolean success = true;
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        try {
            // 设置lenient为false. 否则SimpleDateFormat会比较宽松地验证日期，比如2007/02/29会被接受，并转换成2007/03/01
            format.setLenient(false);
            format.parse(str);
        } catch (Exception exception) {
            success = false;
        }
        return success;
    }

    /**
     * 判断Email
     */
    public static boolean isEmail(String string) {
        boolean rtn = validByRegex("(\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*)*", string);
        return rtn;
    }

    /**
     * 判断手机号
     */
    public static boolean isMobile(String string) {
        boolean rtn = false;
        if (null != string) {
            rtn = validByRegex("^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\\d{8})$", string);
        }

        return rtn;
    }

    /**
     * 判断固定电话
     */
    public static boolean isPhone(String string) {
        boolean rtn = false;
        if (null != string) {
            rtn = validByRegex("(0[0-9]{2,3}\\-)?([2-9][0-9]{6,7})+(\\-[0-9]{1,4})?", string);
        }

        return rtn;
    }

    /**
     * 判断zip
     */
    public static boolean isZip(String string) {
        boolean rtn = validByRegex("^[0-9]{6}$", string);
        return rtn;
    }

    /**
     * 判断QQ
     */
    public static boolean isQq(String string) {
        boolean rtn = validByRegex("^[1-9]\\d{4,9}$", string);
        return rtn;
    }

    /**
     * 判断IP
     */
    public static boolean isIp(String string) {
        boolean rtn = validByRegex("^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}" +
                "(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$", string);
        return rtn;
    }

    /**
     * 判断中文
     */
    public static boolean isChinese(String string) {
        boolean rtn = validByRegex("^[一-龥]+$", string);
        return rtn;
    }

    /**
     * 判断2-15位的中文汉字
     */
    public static boolean isChineseLetter(String string) {
        boolean rtn = validByRegex("^[\\u4e00-\\u9fa5]{2,15}$", string);
        return rtn;
    }

    /**
     * 判断字母 数字
     */
    public static boolean isChrNum(String string) {
        // boolean rtn = validByRegex("^([a-zA-Z0-9]+)$", string);
        boolean rtn = validByRegex("(\\d{14}[0-9a-zA-Z])|(\\d{17}[0-9a-zA-Z])", string);

        return rtn;
    }

    /**
     * 判断URL
     */
    public static boolean isUrl(String url) {
        return validByRegex("(http://|https://)?([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?", url);
    }

    /**
     * 通过正则表达式验证
     */
    public static boolean validByRegex(String regex, String input) {
        Pattern pattern = Pattern.compile(regex, 2);
        Matcher regexMatcher = pattern.matcher(input);
        return regexMatcher.find();
    }

    /**
     * 第一个字母大写
     */
    public static String makeFirstLetterUpperCase(String newStr) {
        if (newStr.length() == 0) {
            return newStr;
        }
        char[] oneChar = new char[1];
        oneChar[0] = newStr.charAt(0);
        String firstChar = new String(oneChar);
        return new StringBuilder().append(firstChar.toUpperCase()).append(newStr.substring(1)).toString();
    }

    /**
     * 第一个字母小写
     */
    public static String makeFirstLetterLowerCase(String newStr) {
        if (newStr.length() == 0) {
            return newStr;
        }
        char[] oneChar = new char[1];
        oneChar[0] = newStr.charAt(0);
        String firstChar = new String(oneChar);
        return new StringBuilder().append(firstChar.toLowerCase()).append(newStr.substring(1)).toString();
    }

    /**
     * 格式化参数信息
     *
     * @param message 消息
     * @param args    Object[]
     * @return String
     */
    public static String formatParamMsg(String message, Object[] args) {
        for (int i = 0; i < args.length; i++) {
            message = message.replace(new StringBuilder().append("{").append(i).append("}").toString(),
                    args[i].toString());
        }
        return message;
    }

    /**
     * 格式化参数信息
     *
     * @param message 消息
     * @param params  Map
     * @return String
     */
    public static String formatParamMsg(String message, @SuppressWarnings("rawtypes") Map params) {
        if (params == null) {
            return message;
        }
        @SuppressWarnings("rawtypes")
        Iterator keyIts = params.keySet().iterator();
        while (keyIts.hasNext()) {
            String key = (String) keyIts.next();
            Object val = params.get(key);
            if (val != null) {
                message = message.replace(new StringBuilder().append("${").append(key).append("}").toString(),
                        val.toString());
            }
        }
        return message;
    }

    /**
     * 格式化消息
     */
    public static StringBuilder formatMsg(CharSequence msgWithFormat, boolean autoQuote, Object[] args) {
        int argsLen = args.length;
        boolean markFound = false;

        StringBuilder sb = new StringBuilder(msgWithFormat);

        if (argsLen > 0) {
            for (int i = 0; i < argsLen; i++) {
                String flag = new StringBuilder().append("%").append(i + 1).toString();
                int idx = sb.indexOf(flag);

                while (idx >= 0) {
                    markFound = true;
                    sb.replace(idx, idx + 2, toString(args[i], autoQuote));
                    idx = sb.indexOf(flag);
                }
            }

            if ((args[(argsLen - 1)] instanceof Throwable)) {
                StringWriter sw = new StringWriter();
                // ((Throwable) args[(argsLen - 1)]).printStackTrace(new PrintWriter(sw));
                sb.append("\n").append(sw.toString());
            } else if ((argsLen == 1) && (!markFound)) {
                sb.append(args[(argsLen - 1)].toString());
            }
        }
        return sb;
    }

    public static StringBuilder formatMsg(String msgWithFormat, Object[] args) {
        return formatMsg(new StringBuilder(msgWithFormat), true, args);
    }

    /**
     * toString方法
     */
    public static String toString(Object obj, boolean autoQuote) {
        StringBuilder sb = new StringBuilder();
        if (obj == null) {
            sb.append("NULL");
        } else if ((obj instanceof Object[])) {
            for (int i = 0; i < ((Object[]) obj).length; i++) {
                sb.append(((Object[]) obj)[i]).append(", ");
            }
            if (sb.length() > 0) {
                sb.delete(sb.length() - 2, sb.length());
            }
        } else {
            sb.append(obj.toString());
        }

        if ((autoQuote) && (sb.length() > 0) && ((sb.charAt(0) != '[') || (sb.charAt(sb.length() - 1) != ']'))
                && ((sb.charAt(0) != '{') || (sb.charAt(sb.length() - 1) != '}'))) {
            sb.insert(0, "[").append("]");
        }
        return sb.toString();
    }

    /**
     * 返回空格
     */
    public static String returnSpace(String str) {
        String space = "";
        if (!str.isEmpty()) {
            String[] path = str.split("\\.");
            for (int i = 0; i < (path.length - 1); i++) {
                space = new StringBuilder().append(space).append("&nbsp;&emsp;").toString();
            }
        }
        return space;
    }

    /**
     * Md5加密
     */
    public static synchronized String encryptMd5(String sourceStr) {

        String result = "";
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(sourceStr.getBytes());
            byte[] bytes = md.digest();
            int index;
            StringBuffer buf = new StringBuffer("");
            for (int offset = 0; offset < bytes.length; offset++) {
                index = bytes[offset];
                if (index < 0) {
                    index += 256;
                }
                if (index < 16) {
                    buf.append("0");
                }
                buf.append(Integer.toHexString(index));
            }
            result = buf.toString();
            // System.out.println("MD5(" + sourceStr + ",32) = " + result);
            // System.out.println("MD5(" + sourceStr + ",16) = " + buf.toString().substring(8, 24));
        } catch (NoSuchAlgorithmException noSuchAlgorithmException) {
            // System.out.println(noSuchAlgorithmException);
        }
        return result;

    }

    /**
     * 得到String类型的数组
     *
     * @param arr List
     */
    public static String getArrayAsString(List<String> arr) {
        if ((arr == null) || (arr.size() == 0)) {
            return "";
        }
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < arr.size(); i++) {
            if (i > 0) {
                sb.append(",");
            }
            sb.append(arr.get(i));
        }
        return sb.toString();
    }

    /**
     * 得到String类型的数组
     *
     * @param arr String[]
     */
    public static String getArrayAsString(String[] arr) {
        if ((arr == null) || (arr.length == 0)) {
            return "";
        }
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < arr.length; i++) {
            if (i > 0) {
                sb.append(",");
            }
            sb.append(arr[i]);
        }
        return sb.toString();
    }

    /**
     * 得到String类型的数组
     *
     * @param set Set
     */
    public static String getSetAsString(@SuppressWarnings("rawtypes") Set set) {
        if ((set == null) || (set.size() == 0)) {
            return "";
        }
        StringBuffer sb = new StringBuffer();
        int index = 0;
        @SuppressWarnings("rawtypes")
        Iterator it = set.iterator();
        while (it.hasNext()) {
            if (index++ > 0) {
                sb.append(",");
            }
            sb.append(it.next().toString());
        }
        return sb.toString();
    }

    /**
     * 大写金额
     */
    public static String hangeToBig(double value) {
        char[] hunit = {'拾', '佰', '仟'};
        char[] vunit = {'万', '亿'};
        char[] digit = {38646, '壹', 36144, '叁', 32902, '伍', 38470, '柒', '捌', '玖'};
        double midVal = value * 100.0D;
        String valStr = String.valueOf(midVal);

        String head = valStr.substring(0, valStr.length() - 2);
        String rail = valStr.substring(valStr.length() - 2);

        String prefix = "";
        String suffix = "";

        if ("00".equals(rail)) {
            suffix = "整";
        } else {
            suffix =
                    new StringBuilder().append(digit[(rail.charAt(0) - '0')]).append("角").append(digit[(rail.charAt(1) - '0')])
                    .append("分").toString();
        }

        char[] chDig = head.toCharArray();
        char zero = '0';
        byte zeroSerNum = 0;
        for (int i = 0; i < chDig.length; i++) {
            int idx = (chDig.length - i - 1) % 4;
            int vidx = (chDig.length - i - 1) / 4;
            if (chDig[i] == '0') {
                zeroSerNum = (byte) (zeroSerNum + 1);
                if (zero == '0') {
                    zero = digit[0];
                } else if ((idx == 0) && (vidx > 0) && (zeroSerNum < 4)) {
                    prefix = new StringBuilder().append(prefix).append(vunit[(vidx - 1)]).toString();
                    zero = '0';
                }
            } else {
                zeroSerNum = 0;
                if (zero != '0') {
                    prefix = new StringBuilder().append(prefix).append(zero).toString();
                    zero = '0';
                }
                prefix = new StringBuilder().append(prefix).append(digit[(chDig[i] - '0')]).toString();
                if (idx > 0) {
                    prefix = new StringBuilder().append(prefix).append(hunit[(idx - 1)]).toString();
                }
                if ((idx == 0) && (vidx > 0)) {
                    prefix = new StringBuilder().append(prefix).append(vunit[(vidx - 1)]).toString();
                }
            }
        }
        if (prefix.length() > 0) {
            prefix = new StringBuilder().append(prefix).append('圆').toString();
        }
        return new StringBuilder().append(prefix).append(suffix).toString();
    }

    public static String jsonUnescape(String str) {
        return str.replace("&quot;", "\"").replace("&nuot;", "\n");
    }

    /**
     * htmlEntityToString
     */
    public static String htmlEntityToString(String dataStr) {
        dataStr =
                dataStr.replace("&apos;", "'").replace("&quot;", "\"").replace("&gt;", ">").replace("&lt;", "<").replace("&amp;", "&");

        int start = 0;
        int end = 0;
        StringBuffer buffer = new StringBuffer();

        while (start > -1) {
            int system = 10;
            if (start == 0) {
                int txt = dataStr.indexOf("&#");
                if (start != txt) {
                    start = txt;
                }
                if (start > 0) {
                    buffer.append(dataStr.substring(0, start));
                }
            }
            end = dataStr.indexOf(";", start + 2);
            String charStr = "";
            if (end != -1) {
                charStr = dataStr.substring(start + 2, end);

                char chars = charStr.charAt(0);
                if ((chars == 'x') || (chars == 'X')) {
                    system = 16;
                    charStr = charStr.substring(1);
                }
            }
            try {
                char letter = (char) Integer.parseInt(charStr, system);
                buffer.append(new Character(letter).toString());
            } catch (NumberFormatException numberFormatException) {
                // numberFormatException.printStackTrace();
            }

            start = dataStr.indexOf("&#", end);
            if ((start - end) > 1) {
                buffer.append(dataStr.substring(end + 1, start));
            }

            if (start == -1) {
                int length = dataStr.length();
                if ((end + 1) != length) {
                    buffer.append(dataStr.substring(end + 1, length));
                }
            }
        }
        return buffer.toString();
    }

    /**
     * stringToHtmlEntity
     */
    public static String stringToHtmlEntity(String str) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < str.length(); i++) {
            char chars = str.charAt(i);

            switch (chars) {
                case '\n':
                    sb.append(chars);
                    break;
                case '<':
                    sb.append("&lt;");
                    break;
                case '>':
                    sb.append("&gt;");
                    break;
                case '&':
                    sb.append("&amp;");
                    break;
                case '\'':
                    sb.append("&apos;");
                    break;
                case '"':
                    sb.append("&quot;");
                    break;
                default:
                    if ((chars < ' ') || (chars > '~')) {
                        sb.append("&#x");
                        sb.append(Integer.toString(chars, 16));
                        sb.append(';');
                    } else {
                        sb.append(chars);
                    }
                    break;
            }
        }
        return sb.toString();
    }

    /**
     * String编码
     */
    public static String encodingString(String str, String from, String to) {
        String result = str;
        try {
            result = new String(str.getBytes(from), to);
        } catch (Exception exception) {
            result = str;
        }
        return result;
    }

    /**
     * 字符串转换成double型数字
     */
    public static double toDouble(String src) {
        double dest = 0.0d;
        try {
            dest = Double.parseDouble(src);
        } catch (Exception exception) {
        }
        return dest;
    }

    /**
     * 字符串转换成float型数字
     */
    public static float toFloat(String src) {
        float dest = 0.0f;
        try {
            dest = Float.parseFloat(src);
        } catch (Exception exception) {
        }
        return dest;
    }

    /**
     * 字符串转换成Int型数字
     */
    public static int toInt(String src) {
        int dest = 0;
        if ((src == null) || src.trim().equals("")) {
            return 0;
        }

        try {
            dest = Integer.parseInt(src.trim());
        } catch (Exception exception) {
        }
        return dest;
    }

    /**
     * 字符串转换成Long型数字
     */
    public static long toLong(String src) {
        long dest = 0;
        if ((src == null) || src.trim().equals("")) {
            return 0;
        }

        try {
            dest = Long.parseLong(src.trim());
        } catch (Exception exception) {
        }
        return dest;
    }

    /**
     * 去空.
     *
     * @param str 传入参数
     * @return String
     */
    public static String isCheckNull(String str) {
        if ((null == str) || (str.length() <= 0) || "null".equals(str) || "NULL".equals(str)) {
            return "";
        }
        return str;
    }

    /**
     * 去空.
     *
     * @param str 传进来的字符串
     * @return String
     */
    public static String rePlaceNullToBar(String str) {
        return isNull(str) == true ? str : (str = str.trim());
    }

    /**
     * 判断字符串是null.
     *
     * @param str 传进来的字符串
     * @return boolean
     */
    public static boolean isNull(String str) {
        return (null == str) || "".equals(str.trim()) || Pattern.matches("^[ ]+$", str);
    }

    /**
     * 判断字符串不为null.
     *
     * @param str 传进来的字符串
     * @return boolean
     */
    public static boolean isNotNull(String str) {
        if ((null != str) && (str.length() > 0) && !"null".equals(str) && !"NULL".equals(str)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 根据指定字符串截取
     */
    public static String[] getSpitString(String obj, String str) {
        String[] arrys = null;
        if ((null != obj) && !"".equals(obj)) {
            arrys = obj.split(str);
        }
        return arrys;
    }

    /**
     * 身份证效验
     */
    public static boolean isIdcardNum(String idcardNum) {
        if (StringUtil.isNull(idcardNum)) {
            return false;
        }
        CheckIdCard checkIdCard = new CheckIdCard();
        checkIdCard.setCardNumber(idcardNum);
        if (!checkIdCard.validate()) {
            return false;
        }

        return true;
    }

    public static String inputStreamToString(InputStream inStream) {
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024];
        int len = 0;
        byte[] data;
        String str = "";
        try {
            while ((len = inStream.read(buffer)) != -1) {
                outStream.write(buffer, 0, len);
            }
            data = outStream.toByteArray(); // 网页的二进制数据
            str = new String(data, "UTF-8");
        } catch (IOException ex) {
        } finally {

            try {
                outStream.close();
                inStream.close();
            } catch (IOException ex) {
            }
        }
        return str;
    }


    /**
     * 时分补全功能
     */
    public static String hoursMinuteFormart(String hm) {
        if (StringUtil.isNull(hm)) {
            return "00:00";
        }
        String hours = hm.split(":")[0];
        String minute = hm.split(":")[1];
        if (hours.length() == 0) {
            hours = "00";
        } else if (hours.length() == 1) {
            hours = "0" + hours;
        }

        if (minute.length() == 0) {
            hours = "00";
        } else if (minute.length() == 1) {
            minute = "0" + minute;
        }
        return hours + ":" + minute;
    }

    /**
     * 时分补全功能
     */
    public static String hoursMinuteFormart(int iHours, int iMinute) {

        String hours = String.valueOf(iHours);
        String minute = String.valueOf(iMinute);
        if (hours.length() == 0) {
            hours = "00";
        } else if (hours.length() == 1) {
            hours = "0" + hours;
        }

        if (minute.length() == 0) {
            hours = "00";
        } else if (minute.length() == 1) {
            minute = "0" + minute;
        }
        return hours + ":" + minute;
    }


    /**
     * updatedBy--106869:zdl
     * version:1.0
     * 隐藏数字显示*
     *
     * @param formatString   需要显示*的字符串
     * @param starStartIndex *开始的位置
     * @param starEndIndex   *结束的位置
     * @return result 处理后的结果字符串
     */
    public static String formatShowStarString(String formatString, int starStartIndex, int starEndIndex) {
        String result = formatString;

        if (isNotEmpty(formatString) && formatString.length() > starStartIndex) {
            String starString = "";
            for (int i = 0; i < starEndIndex - starStartIndex; i++) {
                starString += "*";
            }
            result = formatString.substring(0, starStartIndex) + starString + formatString.substring(starEndIndex,
                    formatString.length());
        }
        return result;
    }


}